package com.example.isoftservice.service.impl;

import com.example.isoftservice.mapper.DealerTypeMapper;
import com.example.isoftservice.pojos.DealerType;
import com.example.isoftservice.service.DealerTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DealerTypeServiceImpl implements DealerTypeService {

    @Resource
    private DealerTypeMapper dealerTypeMapper;
    @Override
    @Cacheable(cacheNames ="dealerType",key="#pageNo+pageSize")
    public Map<String, Object> searchList(Integer pageNo, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(pageNo,pageSize);
        List<Map<String,Object>> resultList = dealerTypeMapper.selectList();
        PageInfo<Map<String, Object>> info = new PageInfo<>(resultList);
        map.put("total",info.getTotal());
        map.put("rows",info.getList());
        return map;
    }

    @Override
    @Cacheable(cacheNames ="dealerType",key="#dealerTypeId")
    public DealerType searchById(Integer dealerTypeId) {
        return dealerTypeMapper.selectById(dealerTypeId);
    }

    @Override
    @CacheEvict(cacheNames = "dealerType" ,allEntries = true)
    public Boolean addInfo(DealerType dealerType) {
        return dealerTypeMapper.insertInfo(dealerType) == 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "dealerType" ,allEntries = true)

    public Boolean removeByIds(Integer[] ids) {
        return dealerTypeMapper.deleteByIds(ids) >= 1 ? true : false;
    }

    @Override
    @CacheEvict(cacheNames = "dealerType" ,allEntries = true)
    public Boolean modifyById(DealerType dealerType) {
        return dealerTypeMapper.updateById(dealerType) == 1 ? true : false;
    }
}
